#ifndef _CKMSGQUEUE_H_
#define _CKMSGQUEUE_H_



#include "CKBlockingQueue.h"
#include "CKDistributed.h"

namespace K_Engine
{	
	class CKDistributed;
	typedef void  (*setworkfunc)(void*, std::string);
		
	class CKMsgQueue
	{
	private:
		CKBlockingQueue<std::string> m_queue;
		std::string m_tempfile;
		std::string m_strLastError;
		setworkfunc m_setworkfunc;
		CKDistributed *m_distributed;
		bool m_right;
		bool m_run;
		
	public:
		CKMsgQueue();
		~CKMsgQueue();
		
		std::string strGetLastError();
		bool init(std::string strTempMsgFile);
		void PushMsg(std::string msg);
		void KillMQDealMsg();
		void SetDistributed(CKDistributed *distributed);
		
		/**
		 * 消息体处理函数(占用thread)
		 * @Author : Kai.Leung
		 * @Date   : 2016-3-29
		 */
		void MessageLoop(void* SetWorkObject, setworkfunc _setworkfunc);
		
	protected:
		void ChangeMsgCacheFile(std::string tempfile);
		std::string PopMsg();
		void SetLastError(std::string strlasterror);
		void CacheMsgInFile();
		void LoadMsgInFile();
		void Clear();
	};
}

#endif // ! _CKMSGQUEUE_H_